package br.com.portal.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import br.com.portal.beans.CondicaoPagamento;
import br.com.portal.dao.CondicaoPagamentoDAO;

@WebServlet("/BuscarCondicaoPagamento")
public class BuscarCondicaoPagamento extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public BuscarCondicaoPagamento() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Gson gson = new Gson();
		PrintWriter resposta = response.getWriter();
		
		try {
			List<CondicaoPagamento> condicoes = CondicaoPagamentoDAO.buscarCondicaoPagamento();
			String ret = "{items: " + gson.toJson(condicoes) + " }";
			resposta.print(ret);
		} catch (Exception e) {
			resposta.print(e.getMessage());
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}